/* Copyright 2011 Gilberto Pacheco Gallegos.
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
 * this file except in compliance with the License. You may obtain a copy of the
 * License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software distributed
 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.  */
package net.ramptors.dominiobd.client.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Version;

/**
 * @author Gilberto Pacheco Gallegos
 */
@Entity
public class Usuario implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  private String id;
  @Version
  private Integer version;
  /** Contraseña del usuario. */
  private String contrasena;
  /** Nombres del usuario. */
  private String nombres;
  /** Apellidos del usuario. */
  private String apellidos;
  /** Email del usuario. */
  private String email;
  @Basic(fetch= FetchType.EAGER)
  private Set<String> grupos = new HashSet<String>();
  public Usuario() {
  }
  public Usuario(final String id, final Integer version, final String contrasena,
      final String nombres, final String apellidos, final String email,
      final Set<String> grupos) {
    this.id = id;
    this.version = version;
    this.contrasena = contrasena;
    this.nombres = nombres;
    this.apellidos = apellidos;
    this.email = email;
    this.grupos = new HashSet<String>(grupos);
  }
  public String getId() {
    return id;
  }
  public void setId(String id) {
    this.id = id == null ? "" : id.trim();
  }
  public Integer getVersion() {
    return version;
  }
  public String getContrasena() {
    return contrasena;
  }
  public void setContrasena(String contrasena) {
    this.contrasena = contrasena == null ? "" : contrasena.trim();
  }
  public String getNombres() {
    return nombres;
  }
  public void setNombres(String nombres) {
    this.nombres = nombres == null ? "" : nombres.trim();
  }
  public String getApellidos() {
    return apellidos;
  }
  public void setApellidos(String apellidos) {
    this.apellidos = apellidos == null ? "" : apellidos.trim();
  }
  public String getEmail() {
    return email;
  }
  public void setEmail(String email) {
    this.email = email == null ? "" : email.trim();
  }
  public Set<String> getGrupos() {
    return grupos;
  }
  public void setGrupos(Set<String> grupos) {
    this.grupos = grupos;
  }
  @Override
  public int hashCode() {
    if (id == null) {
      return 0;
    } else {
      return id.hashCode();
    }
  }
  @Override
  public boolean equals(Object objeto) {
    if (objeto != null && getClass() == objeto.getClass()) {
      Usuario other = (Usuario) objeto;
      if (this.getId() == null) {
        return other.getId() == null;
      } else {
        return this.getId().equals(other.getId());
      }
    } else {
      return false;
    }
  }
  @Override
  public String toString() {
    return "Usuario[" + id + "]";
  }
}